package cn.juan;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.TreeMap;
import java.util.stream.Stream;

class Book implements Comparable<Book>{
    private int bid;
    private String bname;
    private float price;

    public Book(int bid, String bname, float price) {
        this.bid = bid;
        this.bname = bname;
        this.price = price;
    }

    @Override
    public String toString() {
        return "Book{" +
                "bid=" + bid +
                ", bname='" + bname + '\'' +
                ", price=" + price +
                '}';
    }

    public int getBid() {
        return bid;
    }

    public void setBid(int bid) {
        this.bid = bid;
    }

    public String getBname() {
        return bname;
    }

    public void setBname(String bname) {
        this.bname = bname;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    @Override
    public int compareTo(Book o) {
        return (int) (this.getPrice()-o.getPrice());
    }
}
public class day6homework {
    public static void main(String[] args) {
        TreeMap输出();
        List的流输出();
    }

    private static void List的流输出() {
        ArrayList<Book> list=new ArrayList<>();
        list.add(new Book(1,"西游记",200f));
        list.add(new Book(2,"东游记",180f));
        list.add(new Book(3,"北游记",110f));
        list.add(new Book(4,"南游记",222f));
        list.add(new Book(5,"中游记",140f));

        Stream<Book> s3=list.stream();
        s3.filter(book -> book.getPrice()<150).sorted(new Comparator<Book>() {
            @Override
            public int compare(Book o1, Book o2) {
                return o1.getBid()-o2.getBid();
            }
        }).forEach(System.out::println);
    }

    private static void TreeMap输出() {
        TreeMap<Book,String> map = new TreeMap<>();
        map.put(new Book(1,"西游记",200f),"张三");
        map.put(new Book(2,"东游记",180f),"李四");
        map.put(new Book(3,"北游记",190f),"王五");
        map.put(new Book(4,"南游记",222f),"赵六");
        map.put(new Book(5,"中游记",202f),"孙七");
        map.keySet().forEach(System.out::println);
        System.out.println("============");
        map.entrySet().forEach(System.out::println);
    }
}

